package business.global.pk.tdk;

import java.util.*;

import BaseCommon.CommLog;
import business.global.room.base.AbsRoomPos;
import business.global.room.base.AbsRoomSet;
import business.global.room.base.RoomPlayBack;
import business.tdk.c2s.cclass.*;
import business.tdk.c2s.iclass.*;
import cenum.RoomTypeEnum;
import cenum.mj.MJSpecialEnum;
import cenum.room.SetState;
import cenum.room.TrusteeshipState;
import com.ddm.server.common.CommLogD;
import com.ddm.server.common.utils.CommTime;
import com.ddm.server.websocket.def.ErrorCode;
import com.ddm.server.websocket.handler.requset.WebSocketRequest;
import com.google.gson.Gson;

import cenum.PrizeType;
import jsproto.c2s.cclass.BaseSendMsg;
import jsproto.c2s.cclass.pk.BasePocker;
import jsproto.c2s.cclass.playback.PlayBackData;
import jsproto.c2s.cclass.pos.RoomPlayerPos;
import jsproto.c2s.cclass.room.BaseResults;
import jsproto.c2s.cclass.room.GetRoomInfo;
import jsproto.c2s.iclass.S_GetRoomInfo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;


/**
 * 吹牛一局游戏逻辑
 *
 * @author Administrator
 */
public class TDKRoomSet extends AbsRoomSet {
    /**
     * 当局状态
     */
    protected SetState state = SetState.Init;
    /**
     * 当前回合
     */
    private TDKSetRound curRound = null;
    /**
     * 历史回合
     */
    protected List<TDKSetRound> historyRound = new ArrayList<>();
    protected int dPos = 0;
    // 延迟发牌的时间
    protected int InitTime = 500;
    // 等待时间
    protected int WaitingTime = 5500;
    public long waitingMS = 0;
    // 每个位置信息
    protected Hashtable<Integer, TDKSetPos> posDict = new Hashtable<>();
    // 吹牛-牌管理
    private TDKSetCard setCard = null;
    // 吹牛-房间
    private TDKRoom room = null;
    // 本局玩家位置管理
    private TDKSetPosMgr setPosMgr = null;
    // 最后操作的时间
    protected int lastShotTime = 0;
    private TDK_SetEnd setEnd = new TDK_SetEnd();
    private int winPos = -1;
    protected RoomPlayBack roomPlayBack;        //回放

    // 此轮第1个出牌人的位置与筹码：押注
    private int curOpPos = -1;
    private int curChip = 0;
    private int totalChip = 0;


    // 扎刀次数  ==>> 末脚踢服次数
    private int zhaDaoNum = 1;

    // 正常压注，根注=false, 是不是T局, 此值第
    private boolean isTiRound = false;

    private boolean isAtLast = false;

    //为不影响正常已经测试过的逻辑，加此字段绕开
    private boolean isMoJiaoTiFuRound=false;
    private int maxPointPos = 0;
    private List<Integer> chipList = new ArrayList<>();
    // 神牌字典
    private HashMap<Long, Integer> godCardMap = new HashMap<>();
    private boolean isAllQiPai = false;
    // 弃牌位置
    private int qiPaiPos = -1;
    private boolean isSetEnd = false;

    private boolean isRunLanguoFun=false;
    // 上轮牌最大的先发
    private int upperRoundMaxPos;
    // 是否烂锅
    private boolean isLanGuo = false;
    // 烂锅倍数
    private int languoBeishu = 0;
    //-1：表示没有人上分中
    private int shangFenPos=-1;
    //点击上分时的时间
    private int shangFenOpTime=0;




    @SuppressWarnings("rawtypes")
    public TDKRoomSet(int setID, TDKRoom room, int dPos) {
        super(setID);
        this.room = room;
        this.dPos = dPos;
        // 设置上轮牌最大的Pos
        this.setUpperRoundMaxPos(this.getdPos());
        this.addGameConfig();
        this.startSet();
    }

    /**
     * 标识Id
     *
     * @return
     */
    @Override
    public int getTabId() {
        return this.room.getTabId();
    }

    /**
     * 测试用
     */
    public TDKRoomSet() {
        super(0);
        startSetTest();
    }

    public void clean() {
        if (null != this.posDict) {
            this.posDict.forEach((key, value) -> {
                if (null != value) {
                    value.clean();
                }
            });
            this.posDict.clear();
            this.posDict = null;
        }

        if (null != setCard) {
            this.setCard.clean();
            this.setCard = null;
        }

        this.cleanEndSetRoom();
        this.setBo(null);
        this.room = null;
        this.setPosMgr = null;
        this.setEnd = null;
        this.chipList = null;
        this.godCardMap = null;

    }

    /**
     * 获取房间回放记录
     *
     * @return
     */
    public RoomPlayBack getRoomPlayBack() {
        if (null == this.roomPlayBack) {
            this.roomPlayBack = new TDKRoomPlayBackImpl(this.room);
        }
        return this.roomPlayBack;
    }


    /**
     * 当前玩家数  YSJVB  TODO 不能根据位置数，要根据实际完游戏的人数。
     *
     * @return
     */
    public int getPlayingCount() {
        return this.posDict.size();
    }

    /**
     * 加入神牌
     *
     * @param pid
     * @param msg
     */
    public boolean addGodCardMap(long pid, String msg) {
        if (StringUtils.isEmpty(msg)) {
            return false;
        }
        int godCard = 0;
        if (msg.startsWith("0x") || msg.startsWith("0X")) {
//            godCard = Integer.parseInt(msg.substring(2), 16);
            godCard = Integer.parseInt(msg.substring(2));
        } else if (!StringUtils.isNumeric(msg)) {
            return false;
        } else {
            godCard = Integer.parseInt(msg);
        }

        if (godCard <= 0) {
            return false;
        }else {
            this.godCardMap.put(pid, godCard);
            //将牌移到最后 panvc
            if(CollectionUtils.isNotEmpty(this.setCard.leftCards)){
                int index = this.setCard.leftCards.indexOf(godCard);
                if (index != -1) {
                    Integer remove = this.setCard.leftCards.remove(index);
                    this.setCard.leftCards.add(remove);
                }
            }
            return true;
        }
    }

    /**
     * 获取牌
     *
     * @param setPos
     * @return
     */
    public TDKCard popCard(TDKSetPos setPos,boolean isLast) {
        TDKCard card;
        if (this.room.getConfigMgr().isGodCard() || (room.getConfigMgr().isDebug() && this.room.getConfigMgr().isDebugUser(setPos.getPid()))) {
            List<Integer> forceInitCard = getAllPrivateCard().get(setPos.getPosID());
            if (forceInitCard.size() >= setPos.getPrivateCards().size() + 1) {
                int startIndex = setPos.getPrivateCards().size();
                List<Integer> tempCards = forceInitCard.subList(startIndex, startIndex + 1);
                List<Integer> popCards = this.setCard.godPopList(tempCards);
                if (tempCards.size() == 1 && tempCards.size() == popCards.size() && tempCards.get(0).equals(popCards.get(0))) {
                    card = new TDKCard(tempCards.get(0),false);
                } else {
                    card = this.setCard.popCard(isLast);
                }
            } else if(this.godCardMap.containsKey(setPos.getPid())) {
                // 摸牌
                card = this.setCard.popCard(this.godCardMap.get(setPos.getPid()), isLast);
            } else {
                card = this.setCard.popCard(isLast);
            }
        } else if(this.godCardMap.containsKey(setPos.getPid())) {
            // 摸牌
            card = this.setCard.popCard(this.godCardMap.get(setPos.getPid()), isLast);
        } else {
            card = this.setCard.popCard(isLast);
        }
        return card;
    }


    public boolean isGodCard(TDKSetPos setPos, int idxPos, int num) {
        if (this.room.getConfigMgr().isGodCard() || (room.getConfigMgr().isDebug() && this.room.getConfigMgr().isDebugUser(setPos.getPid()))) {
            List<Integer> forceInitCard = getAllPrivateCard().get(idxPos);
            if (forceInitCard.size() >= setPos.getPrivateCards().size() + num) {
                int startIndex = setPos.getPrivateCards().size();
                List<Integer> tempCard = forceInitCard.subList(startIndex, startIndex + num);
                setPos.init(this.setCard.godPopList(tempCard));
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    /**
     * 获取所有人的神牌
     * @return
     */
    public List<List<Integer>> getAllPrivateCard () {
        List<List<Integer>> allPrivateCardList = new ArrayList<>();
        for (int i = 0; i < this.room.getPlayerNum(); i++) {
            AbsRoomPos roomPos = (TDKRoomPos) this.room.getRoomPosMgr().getPosByPosID(i);
            ArrayList<Integer> card = (ArrayList<Integer>) this.room.getConfigMgr().getPrivateCards().get(i);
            if(card != null && (room.getConfigMgr().isDebug() && this.room.getConfigMgr().isDebugUser(roomPos.getPid()))){
                allPrivateCardList.add(card);
            }else {
                allPrivateCardList.add(new ArrayList<>());
            }
        }
        return allPrivateCardList;
    }


    /**
     * 获取人数
     *
     * @return
     */
    public int getPlayerNum() {
        return this.room.getPlayerNum();
    }

    /**
     * 获取当前回合
     *
     * @return
     */
    public TDKSetRound getCurRound() {
        return curRound;
    }

    public int getdPos() {
        return dPos;
    }

    public void setdPos(int dPos) {
        this.dPos = dPos;
    }

    /**
     * 获取下一位操作者位置
     *
     * @param opPos
     * @return
     */
    public int nextOpPos(int opPos) {
        TDKSetPos yPos = null;
        int nextOpPos = 0;
        for (int i = 1; i < this.room.getPlayerNum(); i++) {
            nextOpPos = (opPos + i) % this.room.getPlayerNum();
            yPos = this.posDict.get(nextOpPos);
            // 获取玩家位置信息
            if (null == yPos) {
                continue;
            }
            // 检查玩家是否过(出完牌)
            if (yPos.isQiPai()) {
                continue;
            }
            // 下家出牌
            return nextOpPos;
        }
        endSet();
        return opPos;
    }


    /**
     * 获取下一位踢位置
     *
     * @param opPos
     * @return
     */
    public int nextTiPos(int opPos) {
        TDKSetPos yPos = null;
        int nextOpPos = 0;
        for (int i = 1; i < this.room.getPlayerNum(); i++) {
            nextOpPos = (opPos + i) % this.room.getPlayerNum();
            yPos = this.posDict.get(nextOpPos);
            // 获取玩家位置信息
            if (null == yPos) {
                continue;
            }
            // 检查玩家是否过(出完牌)
            if (yPos.isQiPai()) {
                continue;
            }
            // 检查玩家是否已经踢过
            if (yPos.getCurTiOrBuTi() != null) {
                continue;
            }
            // 下家出牌
            return nextOpPos;
        }
        return opPos;
    }


    /**
     * 获取下一位踢位置
     *
     * @param opPos
     * @return
     */
    public int nextMoJiaoTiFuPos(int opPos) {
        TDKSetPos yPos = null;
        int nextOpPos = 0;
        for (int i = 1; i < this.room.getPlayerNum(); i++) {
            nextOpPos = (opPos + i) % this.room.getPlayerNum();
            yPos = this.posDict.get(nextOpPos);
            // 获取玩家位置信息
            if (null == yPos) {
                continue;
            }
            // 检查玩家是否过(出完牌)
            if (yPos.isQiPai()) {
                continue;
            }
            // 检查玩家是否选了不T
            if (TDKdefine.TDK_OP.BuTi.equals( yPos.getCurTiOrBuTi() )) {
                continue;
            }
            // 下家出牌
            return nextOpPos;
        }
        return opPos;
    }

    /**
     * 是否都T服了，也就是只有1人选了T
     */
    public boolean isAllTiFu() {
        int count=0;
        for (int i = 0; i < this.posDict.size(); i++) {
            TDKSetPos yPos = this.posDict.get(i);
            // 获取玩家位置信息
            if (null == yPos) {
                continue;
            }
            // 检查玩家是否过(出完牌)
            if (yPos.isQiPai()) {
                continue;
            }
            // 检查玩家是否选了不T
            if (TDKdefine.TDK_OP.Ti.equals( yPos.getCurTiOrBuTi()) || TDKdefine.TDK_OP.FanTi.equals( yPos.getCurTiOrBuTi())) {
                count+=1;
            }
        }
        return count==1;
    }

    /**
     * 是否都T或者不T了。
     */
    public boolean isAllTiOrBuTi(){
        int count=0;
        for (int i = 0; i < this.posDict.size(); i++) {
            TDKSetPos yPos = this.posDict.get(i);
            // 获取玩家位置信息
            if (null == yPos) {
                continue;
            }
            // 检查玩家是否过(出完牌)
            if (yPos.isQiPai()) {
                continue;
            }
            // 检查玩家是否选了不T
            if (yPos.getCurTiOrBuTi() ==null) {
                count+=1;
            }
        }
        return count==0;
    }

    /**
     * 获取房间信息
     *
     * @return
     */
    public TDKRoom getRoom() {
        return room;
    }


    /**
     * 开始设置
     */
    public void startSetTest() {
        // 洗底牌
        this.setCard = new TDKSetCard(this);
        // 创建玩家当前局操作
        TDKSetPos setPos = null;
        for (int i = 0; i < this.getPlayerNum(); i++) {
            // 创建玩家
            setPos = new TDKSetPos(i, this);
            this.posDict.put(i, setPos);
            // 初始化玩家牌
            setPos.init(this.setCard.popList(5));
        }
        this.startMS = CommTime.nowMS();
        this.setPosMgr = new TDKSetPosMgr(this);
    }

    public void kickOut( List<Long> pids){
        this.posDict.values().forEach(item->{
            if(pids.contains(item.getPid())){
                item.clearKickOut();
            }
        });
    }


    /**
     * 开始设置
     */
    public void startSet() {
        // 洗底牌
        this.setCard = new TDKSetCard(this);
        // 创建玩家当前局操作
        TDKSetPos setPos = null;
        TDKRoomPos roomPos = null;
        int nextPos = 0;
        for (int i = 0; i < this.room.getPlayerNum(); i++) {
            nextPos = (i + this.getdPos()) % this.room.getPlayerNum();
            roomPos = (TDKRoomPos) this.room.getRoomPosMgr().getPosByPosID(nextPos);
            // 检查位置上是否有玩家
            if (null == roomPos || roomPos.getPid() <= 0L) {
                continue;
            }
            //玩家首局记录需要扣除的报名费
            if(roomPos.getRoomSportsConsume() == 0){
                //设置报名费
                roomPos.setRoomSportsConsume(this.room.cfg.getRoomSportsEveryoneConsume());
            }
            // 创建玩家
            setPos = new TDKSetPos(nextPos, roomPos, this);
            this.posDict.put(nextPos, setPos);

            int cardSize=this.getCardSize();
            // 初始化玩家牌
            if (!isGodCard(setPos, nextPos, cardSize)) {
                setPos.init(this.setCard.popList(cardSize));
            }
            // 检查是否庄家
            int defen = this.room.getRoomCfg().getDifen();
            int dizhu = TDKdefine.TDK_DIFEN_TYPE.getFirstChipSet(defen, this.getLanguoBeishu());
            if (this.getdPos() == nextPos) {
                //YSJVB 不是从第1个开始，从选择的底分开始
                setOpPosValue(nextPos, dizhu);
                setPos.addChip(dizhu);
                //setOpPosValue(nextPos, 1);
            } else {
                genZhu();
                setPos.addChip(dizhu);
            }
        }
        this.godCardPrivate();
        this.startMS = CommTime.nowMS();
        this.setPosMgr = new TDKSetPosMgr(this);
        // 开始发牌
        boolean isMPosOne = true;
        for (AbsRoomPos mPos : this.room.getRoomPosMgr().getAllPosList()) {
            if(mPos.getPid() > 0){
                if (isMPosOne) {
                    GetRoomInfo roomInfo = new GetRoomInfo();
                    this.room.getBaseRoomInfo(roomInfo);
                    this.getRoomPlayBack().addPlaybackList(STDK_PlayBackRoomInfo.make(this.room.getRoomID(),roomInfo),null);
                    this.getRoomPlayBack().playBack2Pos(mPos.getPosID(), STDK_SetStart.make(this.room.getRoomID(), this.getNotify_set(mPos.getPid())), setPosMgr.getAllPlayBackNotify());
                } else {
                    this.room.getRoomPosMgr().notify2Pos(mPos, STDK_SetStart.make(this.room.getRoomID(), this.getNotify_set(mPos.getPid())));
                }
                isMPosOne = false;
            }
        }

        this.room.getRoomPosMgr().setAllLatelyOutCardTime();
        this.room.getTrusteeship().setTrusteeshipState(TrusteeshipState.Normal);
    }

    public boolean isGodUser(long pid){
		return room.getConfigMgr().isGodUser(pid);
    }

    /*
    public static void main(String[] args) {
        List<Integer> chipList = new ArrayList<>();
        chipList.add(1);
        chipList.add(1);
        chipList.add(2);
        chipList.add(2);
        chipList.add(3);
        chipList.add(3);
        chipList.add(4);
        chipList.add(4);

        int xiFen =5;
        int tempXiFen=xiFen;
        Optional<Integer> oi = chipList.stream().filter(item -> item == tempXiFen).findFirst();
        if (oi.isPresent()) {
            boolean isSuccess = chipList.remove(oi.get());
            System.out.println("111 isSuccess:" + isSuccess);
        } else {
            int offset = xiFen;
            for (int i = 0; i < chipList.size(); i++) {
                Integer chip = chipList.get(i);
                if (chip > offset) {
                    chipList.set(i, chip - offset);
                    offset = 0;
                } else if (chip < offset) {
                    System.out.println("I:" + i);
                    chipList.set(i, 0);
                    offset -= chip;
                }
                if(offset==0){
                    break;
                }
            }
            chipList.removeIf(item->item.equals(0));
            xiFen-=offset;
        }
        System.out.println("offset:"+xiFen);
        System.out.println(chipList);
    }
    */

    public static void main(String[] args) {
        List<Integer> chipList = new ArrayList<>();
        int i=0;
        Optional<Integer> opt = chipList.stream().reduce(Integer::sum);
        // int guodi = chipList.stream().reduce(Integer::sum).get();
        int j=opt.isPresent()?opt.get():0;
        // System.out.println(j);
    }

    /**
     * 重新开始设置
     */
    public void resetStartSet() {
        if(this.isRunLanguoFun){
            return;
        }
        this.isRunLanguoFun=true;
        this.curRound = null;
        this.historyRound.clear();
        this.curOpPos = -1;
        this.zhaDaoNum = 1;
        this.isAtLast = false;
        this.isAllQiPai = false;
        this.qiPaiPos = -1;
        this.maxPointPos = 0;
        this.isSetEnd = false;
        this.waitingMS = 0L;
        // 设置上轮牌最大的Pos
        this.setUpperRoundMaxPos(this.getdPos());
        // 洗底牌
        this.setCard = new TDKSetCard(this);
        // 创建玩家当前局操作
        TDKSetPos setPos = null;
        TDKRoomPos roomPos = null;
        // 烂锅推注：即烂锅重新发牌后，重新押注的筹码不能少于烂锅时的最大押注；
        //YSJVB 去掉不要。烂锅下把打翻  TODO 测试好了删除下面注释的代码
        /*
        if (!this.room.languowanfa(TDKdefine.TDK_LANGUO_WANFA.TUIZHU.ordinal())) {
            this.curChip = 1;
        }
        */
        // 设置本局烂锅
        this.setLanGuo(true);
        this.addLanguoBeishu(1);

        if (RoomTypeEnum.UNION.equals(this.getRoom().getRoomTypeEnum())) {
            //YJSVB 抽喜分，给盟主，不分给下级 TODO
            try{
                Optional<Integer> beforeChipOpt = this.chipList.stream().reduce(Integer::sum);
                int guodi =beforeChipOpt.isPresent()?beforeChipOpt.get():0;
                int xiFen=this.getRoom().getBaseRoomConfigure().getBaseCreateRoom().getXiFen();
                int finalXiFen =  Math.min(xiFen, guodi);
                //如过喜分超过锅底，按锅底分算（也就是锅底分全部抽完）
                //从桌面筹码中抽喜分
                int tempXiFen=finalXiFen;
                Optional<Integer> oi = this.chipList.stream().filter(item -> item == tempXiFen).findFirst();
                if (oi.isPresent()) {
                    this.chipList.remove(oi.get());
                } else {
                    int offset = finalXiFen;
                    for (int i = 0; i < this.chipList.size(); i++) {
                        Integer chip = this.chipList.get(i);
                        if (chip >= offset) {
                            this.chipList.set(i, chip - offset);
                            offset = 0;
                        } else if (chip < offset) {
                            this.chipList.set(i, 0);
                            offset -= chip;
                        }
                        if(offset==0){
                            break;
                        }
                    }
                    this.chipList.removeIf(item->item.equals(0));
                }
                //出错原因，喜分被全部抽完
                Optional<Integer> afterChipOpt=this.chipList.stream().reduce(Integer::sum);
                this.totalChip=afterChipOpt.isPresent()?afterChipOpt.get():0;
                this.getRoom().updateClubCreaterXiFen(finalXiFen);
            }catch(Exception e){
                CommLogD.error("抽取喜分出错！！ roomid:"+this.room.getRoomKey()+", setId:"+this.getSetID());
            }

        }

        int nextPos = 0;
        for (int i = 0; i < this.room.getPlayerNum(); i++) {
            nextPos = (i + this.getdPos()) % this.room.getPlayerNum();
            roomPos = (TDKRoomPos) this.room.getRoomPosMgr().getPosByPosID(nextPos);
            // 检查位置上是否有玩家
            if (null == roomPos || roomPos.getPid() <= 0) {
                continue;
            }
            setPos = this.posDict.get(nextPos);
            if (null == setPos) {
                continue;
            }
            // 清空牌
            setPos.clearCards();
            // 初始化玩家牌
            int cardSize=this.getCardSize();
            if (!isGodCard(setPos, nextPos, cardSize)) {
                setPos.init(this.setCard.popList(cardSize));
            }
        }
        this.godCardPrivate();
        this.startMS = CommTime.nowMS();
        this.setPosMgr = new TDKSetPosMgr(this);
        // 开始发牌
        boolean isMPosOne = true;
        for (AbsRoomPos mPos : this.room.getRoomPosMgr().getAllPosList()) {
            if(mPos.getPid() > 0) {
                if (isMPosOne) {
                    GetRoomInfo roomInfo = new GetRoomInfo();
                    this.room.getBaseRoomInfo(roomInfo);
                    this.getRoomPlayBack().addPlaybackList(STDK_PlayBackRoomInfo.make(this.room.getRoomID(),roomInfo),null);
                    this.getRoomPlayBack().playBack2Pos(mPos.getPosID(), STDK_SetStart.make(this.room.getRoomID(), this.getNotify_set(mPos.getPid())), setPosMgr.getAllPlayBackNotify());
                } else {
                    this.room.getRoomPosMgr().notify2Pos(mPos.getPosID(), STDK_SetStart.make(this.room.getRoomID(), this.getNotify_set(mPos.getPid())));
                }
            }
            isMPosOne = false;
        }
        this.room.getRoomPosMgr().setAllLatelyOutCardTime();
        this.room.getTrusteeship().setTrusteeshipState(TrusteeshipState.Normal);

        this.state = SetState.Init;
        this.isRunLanguoFun=false;
    }

    /**
     * 清空T或者不T操作
     *
     * @return
     */
    public void clearTiOrBuTiOp(int posID) {
        TDKSetPos setPos = null;
        int maxPos = -1;
        // 牌值
        int nextPos = 0;
        for (int i = 0; i < this.room.getPlayerNum(); i++) {
            nextPos = (i + posID) % this.room.getPlayerNum();
            setPos = this.posDict.get(nextPos);
            if (null == setPos) {
                continue;
            }
            // 检查弃牌
            if (setPos.isQiPai()) {
                continue;
            }
            //YSJVB 清空isOpTiOrBuTi
            setPos.setCurTiOrBuTi(null);
        }
    }



    /**
     * 清空T或者不T操作
     *
     * @return
     */
    public void clearTiOp(int posID) {
        TDKSetPos setPos = null;
        int maxPos = -1;
        // 牌值
        int nextPos = 0;
        for (int i = 0; i < this.room.getPlayerNum(); i++) {
            nextPos = (i + posID) % this.room.getPlayerNum();
            setPos = this.posDict.get(nextPos);
            if (null == setPos) {
                continue;
            }
            // 检查弃牌
            if (setPos.isQiPai()) {
                continue;
            }
            if(TDKdefine.TDK_OP.BuTi.equals(setPos.getCurTiOrBuTi())){
                continue;
            }
            //YSJVB 清空isOpTiOrBuTi
            setPos.setCurTiOrBuTi(null);
        }
    }

    /**
     * 摸牌
     *
     * @return
     */
    public int doMoPaiAndGetMaxCardPos(int posID) {

        //YSJVB 2023-08-26 从最大的牌开始发:calcNextYaPos 此方法会取上轮牌最大的pos，并且去掉弃牌的
        int upperMaxPos=this.setPosMgr.calcNextYaPos(posID);
        this.setUpperRoundMaxPos(upperMaxPos);

        TDKSetPos setPos = null;
        int maxPos = -1;
        // 牌值
        int nextPos = 0;
        for (int i = 0; i < this.room.getPlayerNum(); i++) {
            nextPos = (i + upperMaxPos) % this.room.getPlayerNum();
            setPos = this.posDict.get(nextPos);
            if (null == setPos) {
                continue;
            }
            // 检查弃牌
            if (setPos.isQiPai()) {
                continue;
            }
            // 摸牌
            TDKCard card = this.popCard(setPos,i==this.room.getPlayerNum()-1);
            int cardID=card.getCard();
            if (cardID <= 0) {
                continue;
            }
            setPos.addCard(cardID);
            // 获取手上牌数量
            int sizeCard = setPos.sizePrivateCard();
            if (sizeCard == 5) {

                //YSJVB 20230911
                if(card.isJiePai()){
                    setPos.setJiepai(true);
                }

                if (this.getRoom().keXuanWanFa(TDKdefine.TDK_KEXUAN.MOJIAOTIFU)) {
                    this.zhaDaoNum = 5;
                } else {
                    this.zhaDaoNum = 1;
                }
                this.setAtLast(true);
            }

            //YSJVB 清空isOpTiOrBuTi
            setPos.setCurTiOrBuTi(null);
        }
        //YSVJB 发牌后清空
        this.isTiRound = false;
        this.curOpPos = -1;
        this.curChip = 0;

        maxPos = this.setPosMgr.calcNextYaPos(this.getUpperRoundMaxPos());
        // 开始发牌
        boolean isMPosOne = true;
        for (AbsRoomPos mPos : room.getRoomPosMgr().getAllPosList()) {
            if(mPos.getPid() > 0){
                if (isMPosOne) {
                    //this.getRoomPlayBack().playBack2Pos(mPos, STDK_PosGetCard.make(this.room.getRoomID(), this.getNotifyCardPos(mPos.getPid()), this.getUpperRoundMaxPos()), setPosMgr.getAllPlayBackNotify());
                    this.getRoomPlayBack().playBack2Pos(mPos, STDK_PosGetCard.make(this.room.getRoomID(), this.getNotifyCardPos(mPos.getPid()), upperMaxPos), setPosMgr.getAllPlayBackNotify());
                } else {
                    //this.room.getRoomPosMgr().notify2Pos(mPos, STDK_PosGetCard.make(this.room.getRoomID(), this.getNotifyCardPos(mPos.getPid()), this.getUpperRoundMaxPos()));
                    this.room.getRoomPosMgr().notify2Pos(mPos, STDK_PosGetCard.make(this.room.getRoomID(), this.getNotifyCardPos(mPos.getPid()),upperMaxPos));
                }
            }
            isMPosOne = false;
        }
        if (this.checkExistPrizeType(PrizeType.Gold)) {
            this.maxPointPos = this.setPosMgr.calcMaxPointPos(TDKdefine.TDK_CALC_TYPE.TDK_CALC_ALL, getDai2Flag());
        }
        // 设置此轮牌最大的Pos
        this.setUpperRoundMaxPos(maxPos);
        return maxPos;

    }

    /*
    public static void main(String[] args) {
        List<String> cards=new ArrayList<>();
        cards.add("A");
        cards.add("B");
        cards.add("C");
        cards.add("D");
        cards.add("E");
        List<String> temp1=cards.subList(0,2);
        List<String> temp2=cards.subList(2,3);
        List<String> temp3=cards.subList(3,4);
        List<String> temp4=cards.subList(4,5);
        System.out.println(temp1);
        System.out.println(temp2);
        System.out.println(temp3);
        System.out.println(temp4);

    }
     */

    /**
     * 神牌模式下补牌
     */
    public void godCardPrivate() {
        int  cardSize=getCardSize();
        if (this.room.getConfigMgr().isGodCard() || room.getConfigMgr().isDebug()) {
            for (int idx = 0; idx < room.getPlayerNum(); idx++) {
                AbsRoomPos roomPos = (TDKRoomPos) this.room.getRoomPosMgr().getPosByPosID(idx);
                if(!this.room.getConfigMgr().isDebugUser(roomPos.getPid())){
                    continue;
                }
                TDKSetPos mSetPos = this.posDict.get(idx);
                if (null == mSetPos) {
                    continue;
                }
                if (mSetPos.sizePrivateCard() == cardSize) {
                    continue;
                }
                int podIdx = cardSize - mSetPos.sizePrivateCard();
                ArrayList<Integer> privateList = this.setCard.popList(podIdx);
                privateList.addAll(mSetPos.getPrivateCards());
                mSetPos.init(privateList);
            }
        }
    }

    /**
     * 获取当局位置管理
     *
     * @return
     */
    public TDKSetPosMgr getSetPosMgr() {
        return this.setPosMgr;
    }

    /**
     * 当局解散
     */
    public void curSetDissolve(boolean isDissolve) {
        this.endSet();
    }

    /**
     * 局结束
     */
    @Override
    public void endSet() {
        //去掉所有人的托管状态，应该能解决卡了下把牌也弃牌了  2023-08-28
        //this.getRoom().getRoomPosMgr().cancleTrusteeship();
        if (SetState.End.equals(this.getState())) {
            return;
        }
        if (this.calcPoint()) {
            this.state = SetState.End;
            this.setEnd(true);
            // 如果是房卡类型，才需要回放记录
            this.setRecordPosInfoList();

            int leftPlayingCount=this.getRoom().getPlayingCount()-this.getRoom().getKillPlayerCount();

            //只有一个人房间结束
            boolean roomEnd = false;
            if(leftPlayingCount <= 1){
                this.getRoom().setAutoDismiss(false);
                this.getRoom().doDissolveRoom(false);
                roomEnd = true;
            }
            // 广播
            this.getRoomPlayBack().playBack2All(STDK_SetEnd.make(this.room.getRoomID(), roomEnd, this.getNotify_setEnd()));
            this.roomPlayBack();

            //房间结束所有人统一结算，不再单独结算，防止被踢的人重复结算
            if(!roomEnd){
                //YSJVB 把要踢的人踢了
                this.getRoom().killPlayerByMengZhuMark();
            }
        }
    }

    public TDKSetRound getHistoryRound(int roundId) {
        return historyRound.get(roundId);
    }

    public void insertPlayerRoomAloneBO() {

    }

    protected void setRecordPosInfoList() {
        //记录玩家信息和简介
        for (AbsRoomPos pos : this.room.getRoomPosMgr().getAllPosList()) {
            TDKRoomPos roomPos = (TDKRoomPos) pos;
            if (roomPos != null && roomPos.getPid() > 0 && roomPos.isPlayTheGame()) {
                RoomPlayerPos roomPlayerPos = roomPos.roomPlayerPos();
                TDKRoom_RecordPosInfo posInfo = roomPos.initAndReturnResult(new TDKRoom_RecordPosInfo());
                TDKRoom_RecordPosInfo leavePosInfo = (TDKRoom_RecordPosInfo) this.room.leavePosInfoList.get(roomPos.getPid());
                if(leavePosInfo != null){
                    roomPlayerPos.addPoint(leavePosInfo.getPoint());
                    roomPlayerPos.addSportsPoint(leavePosInfo.getSportsPoint());
                    posInfo.setPoint(roomPos.getPoint() + leavePosInfo.getPoint());
                    posInfo.setLoseCount(roomPos.getLoseCount() + leavePosInfo.getLoseCount());
                    posInfo.setWinCount(roomPos.getWinCount() + leavePosInfo.getWinCount());
                    posInfo.setSportsPoint(roomPos.sportsPoint() + leavePosInfo.getSportsPoint());
                    posInfo.setJieGuoCount(roomPos.getJieGuoCount() + leavePosInfo.getJieGuoCount());
                }else {
                    posInfo.setPoint(roomPos.getPoint());
                    posInfo.setLoseCount(roomPos.getLoseCount());
                    posInfo.setWinCount(roomPos.getWinCount());
                    posInfo.setSportsPoint(roomPos.sportsPoint());
                    posInfo.setJieGuoCount(roomPos.getJieGuoCount());
                }
                posInfo.setPos(roomPos.getPosID());
                posInfo.setPid(roomPos.getPid());
                posInfo.setSex(roomPos.getSex());
                posInfo.setName(roomPos.getName());
                posInfo.setHeadImageUrl(roomPos.getHeadImageUrl());
                posInfo.setOwner(roomPos.getPid() == this.room.getOwnerID());
                if(roomPos.isLeaveNextSet()){
                    this.room.leavePosInfoList.put(roomPos.getPid(), posInfo);
                }
                this.room.allRecordPosInfoList.put(roomPos.getPid(), posInfo);
                this.room.allPlayerList.put(roomPos.getPid(), roomPlayerPos);
                this.room.allShortPlayer.put(roomPos.getPid(), roomPos.getShortPlayer());
            }
        }
    }

    // 每200ms更新1次 秒
    @Override
    public boolean update(int sec) {
        boolean isClose = false;

        if (this.state == SetState.Init) {
            if (CommTime.nowMS() > this.startMS + this.InitTime) {
                this.state = SetState.Playing;
                if (!this.startNewRound()) {
                    this.endSet();
                }
            }
        } else if (this.state == SetState.Playing) {
            boolean isRoundClosed = this.curRound.update(sec);
            if (isRoundClosed) {
                if (curRound.isSetHuEnd()) {
                    this.endSet();
                } else if (!this.startNewRound()) {
                    this.endSet();
                }
            }
        } else if (this.state == SetState.End) {
            this.cleanEndSetRoom();
            isClose = true;

        } else if (this.state == SetState.Waiting) {
            if (CommTime.nowMS() > this.waitingMS + this.WaitingTime) {
                // 重新开始设置
                this.resetStartSet();
            }
        }
        return isClose;
    }

    @Override
    public void clear() {

    }

    @Override
    public void clearBo() {

    }

    /**
     * 清空结束房间当前局
     */
    public void cleanEndSetRoom() {
        if (null != this.historyRound) {
            this.historyRound.forEach(key -> {
                if (null != key) {
                    key.clean();
                }
            });
            this.historyRound.clear();
            this.historyRound = null;
        }
        // 清空当前回合
        if (null != this.curRound) {
            this.curRound.clean();
            this.curRound = null;
        }
        // 房间回放
        if (null != this.roomPlayBack) {
            this.roomPlayBack.clear();
            this.roomPlayBack = null;
        }
    }

    /**
     * 总回合数
     *
     * @return
     */
    public int sizeHistoryRound() {
        return this.historyRound.size() + 1;
    }

    // 开启新的回合
    public boolean startNewRound() {
        if (this.curRound != null) {
            this.historyRound.add(this.curRound);
        }
        this.curRound = new TDKSetRound(this, this.sizeHistoryRound());
        return this.curRound.tryStartRound();
    }


    public int calcNextDPos() {
        int pos;
        if (this.winPos < 0) {
            pos = this.dPos;
        } else {
            pos = this.winPos;
        }
        //下一位操作者被提出，需要轮换下一位操作者
        if(pos >= 0){
            while (this.room.getRoomPosMgr().getPosByPosID(pos).getPid() == 0){
                pos ++;
                if(pos >= this.room.getPlayerNum()){
                    pos = 0;
                }
            }
        }
        return pos;
    }

    public List<TDKSet_Pos> getNotifyCardPos(long pid) {
        // 每个玩家的牌面
        List<TDKSet_Pos> setPosList = new ArrayList<>();
        TDKSetPos sPos = null;
        for (int i = 0; i < this.room.getPlayerNum(); i++) {
            sPos = this.posDict.get(i);
            if (null == sPos || sPos.getPid() <= 0) {
                continue;
            }
            setPosList.add(sPos.getNotify(sPos.getPid() == pid));
        }
        return setPosList;

    }


    /**
     * 获取每个玩家的牌面
     *
     * @return
     */
    public List<TDKSet_Pos> getNotifyCardPos() {
        // 每个玩家的牌面
        List<TDKSet_Pos> setPosList = new ArrayList<>();
        TDKSetPos sPos = null;
        for (int i = 0; i < this.room.getPlayerNum(); i++) {
            sPos = this.posDict.get(i);
            if (null == sPos || sPos.getPid() <= 0) {
                continue;
            }
            setPosList.add(sPos.getNotify());
        }
        return setPosList;

    }

    /**
     * 获取通知设置
     *
     * @param pid 用户ID
     * @return
     */
    @Override
    public TDKRoomSetInfo getNotify_set(long pid) {
        TDKRoomSetInfo ret = new TDKRoomSetInfo();
        ret.setSetID(this.getSetID());
        ret.startTime = CommTime.nowSecond();
        ret.curOpPos = this.curOpPos;
        ret.curChip = this.curChip;
        ret.totalChip = this.totalChip;
        ret.chipList = this.chipList;
        ret.pos = this.getUpperRoundMaxPos();

        //ysjvb
        ret.dPos=this.getdPos();
        ret.state = this.state; // 当前局状态 Init；End； Playing不需要信息
        ret.isLanGuo = this.isLanGuo();
        ret.languoBeishu = this.getLanguoBeishu();
        // 每个玩家的牌面
        ret.setPosList = new ArrayList<>();

        ret.setShangFenPos(this.shangFenPos);
        ret.setShangFenOpTime(this.shangFenOpTime);
        ret.setShangFenTime(this.getRoom().getShangFenTime());

        TDKSetPos sPos = null;
        if (null == this.room || null == this.posDict) {
            CommLogD.error("TDKRoom_Set null == this.room this.state:{}", this.state);
            return ret;
        }
        for (int i = 0; i < room.getPlayerNum(); i++) {
            sPos = this.posDict.get(i);
            if (null == sPos || sPos.getPid() <= 0) {
                continue;
            }
            ret.setPosList.add(sPos.getNotify(pid == sPos.getPid()));
        }

        // 如果是等待状态： waiting；
        if (this.state == SetState.Playing && null != curRound) {
            //int pos = this.room.getRoomPosMgr().getPosByPid(pid).getPosID();
            int pos = ((TDKRoomPosMgr) this.room.getRoomPosMgr()).getAllPosByPid(pid).getPosID();
            ret.setRound = curRound.getNotify_RoundInfo(pos); // 当前等待信息 Wait
        }
        if (this.state == SetState.End) {
            ret.setEnd = this.getNotify_setEnd(); // 结束状态
        }
        return ret;
    }

    @Override
    public TDK_SetEnd getNotify_setEnd() {
        return setEnd;
    }

    public SetState getState() {
        return state;
    }

    public int getLastShotTime() {
        return lastShotTime;
    }

    public void setLastShotTime(int lastShotTime) {
        this.lastShotTime = lastShotTime;
    }

    /**
     * 烂锅玩法
     */
    private boolean lanGuoPoint() {
        int maxPos = this.setPosMgr.calcMaxPointPosValue(TDKdefine.TDK_CALC_TYPE.TDK_CALC_ALL);
        if (maxPos <= -1) {
            this.state = SetState.Waiting;
            this.waitingMS = CommTime.nowMS();
            // 烂锅通知
            this.getRoomPlayBack().playBack2All(STDK_LanGuo.make(this.room.getRoomID(), this.getNotifyCardPos()));
            return true;
        } else {
            // 算分
//            this.calcMaxPos(maxPos);
            return false;
        }
    }

    /**
     * 正常玩法
     */
    private void normalPoint() {
        // 获取最大分数的位置。
        int maxPos = this.setPosMgr.calcMaxPointPos(TDKdefine.TDK_CALC_TYPE.TDK_CALC_ALL, getDai2Flag());
        if (maxPos < 0) {
            // 获取唯一没有弃牌的玩家位置ID
            maxPos = this.setPosMgr.getNotQiPaiPodID();
        }
        // 算分
        this.calcMaxPos(maxPos);
    }

    /**
     * 算分
     *
     * @param maxPos
     */
    private void calcMaxPos(int maxPos) {
        TDKSetPos setPos = this.posDict.get(maxPos);
        if (null == setPos || setPos.getPid() <= 0) {
            CommLogD.error("calcPoint null == setPos RoomID:{}", this.room.getRoomID());
        } else {
            // 如果本局产生烂锅，则在最后赢家头像边添加一个“接锅”标识；
            if (isLanGuo()) {
                // 标记接锅
                setPos.setJieGuo(true);
            }
            this.winPos = setPos.getPosID();
            TDKSetPos qSetPos = null;
            for (int index = 0; index < room.getPlayerNum(); index++) {
                qSetPos = this.posDict.get(index);
                if (null == qSetPos || qSetPos.getPid() <= 0) {
                    continue;
                }
                if (qSetPos.getPosID() == setPos.getPosID()) {
                    setPos.setSetPoint(setPos.getSetPoint() + totalChip - setPos.getChip());
                }else {
                    qSetPos.setSetPoint(-qSetPos.getChip());
                }
            }
        }
    }


    // 结算积分
    public boolean calcPoint() {
        if (this.isSetEnd) {
            return false;
        }
        this.isSetEnd = true;
        this.getBo().setRoomID(room.getRoomID());
        this.getBo().setSetID(getSetID());
        this.getBo().setTabId(this.room.getTabId());

        // 烂锅玩法算分
        if (this.lanGuoPoint()) {
            return false;
        } else {
            this.normalPoint();
        }

        TDK_PosEnd posEnd;
        // 总结每个人积分
        TDKSetPos sPos = null;
        for (int index = 0; index < room.getPlayerNum(); index++) {
            sPos = posDict.get(index);
            if (null == sPos || sPos.getPid() <= 0) {
                continue;
            }
            posEnd = sPos.calcPosEnd();
            this.setEnd.posResultList.add(posEnd);
        }
        this.lastShotTime = CommTime.nowSecond();
        this.room.getRoomPosMgr().setAllLatelyOutCardTime();
        this.setEnd.endTime = CommTime.nowSecond();
        this.setEnd.playBackCode = getPlayBackDateTimeInfo().getPlayBackCode();
        this.setEnd.setSetId(this.getSetID());
        TDK_SetEnd xSetEnd = this.getNotify_setEnd();
        if (null != xSetEnd) {
            String gsonSetEnd = new Gson().toJson(xSetEnd);
            this.getBo().setDataJsonRes(gsonSetEnd);
        }
        if (this.checkExistPrizeType(PrizeType.Gold)) {
            return true;
        }

        TDK_SetEnd lSetEnd = this.getNotify_setEnd();
        String gsonSetEnd = new Gson().toJson(lSetEnd);
        this.getBo().setDataJsonRes(gsonSetEnd);
        this.getBo().setEndTime(this.setEnd.endTime);
        this.getBo().setPlayBackCode(getPlayBackDateTimeInfo().getPlayBackCode());
        this.getBo().getBaseService().save(this.getBo());
        return true;
    }

    /**
     * 看牌
     *
     * @param request
     * @param opPos
     */
    public void on_kan(WebSocketRequest request, long pid, int opPos) {
        TDKSetPos setPos = this.posDict.get(opPos);
        if (null == setPos || setPos.getPid() <= 0) {
            request.error(ErrorCode.NotAllow, "null == setPos");
            return;
        }
        /*
        if (setPos.isQiPai()) {
            request.error(ErrorCode.NotAllow, "isQiPai == true");
            return;
        }
        */
        if (setPos.getPid() != pid) {
            request.error(ErrorCode.NotAllow, "setPos.getPid() != pid");
            return;
        }
        setPos.setKanPai(true);
        for (int i = 0; i < room.getPlayerNum(); i++) {
            if (i == opPos) {
                this.room.getRoomPosMgr().notify2Pos(i, STDK_Kan.make(this.room.getRoomID(), opPos, setPos.kanPai(), setPos.isKanPai()));
            } else {
                //YSJVB 不用发给其他人
                //this.room.getRoomPosMgr().notify2Pos(i, STDK_Kan.make(this.room.getRoomID(), opPos, null, setPos.isKanPai()));
            }
        }
        request.response();
    }

    public int getCurOpPos() {
        return curOpPos;
    }

    public int getCurChip() {
        return curChip;
    }

    public int getTotalChip() {
        return totalChip;
    }

    /**
     * 本轮操作
     *
     * @param curOpPos 本轮第一位操作者
     * @param curChip  本轮押注值
     */
    public void setOpPosValue(int curOpPos, int curChip) {
        //System.out.println("=============>>CurOpPos:" + curOpPos + ", CurChip:" + curChip);
        this.curOpPos = curOpPos;
        this.curChip = curChip;
        this.totalChip += curChip;
        this.chipList.add(curChip);
    }

    /**
     * 跟注
     */
    public void genZhu() {
        this.totalChip += this.curChip;
        this.chipList.add(this.curChip);
    }

    public boolean isAtLast() {
        return isAtLast;
    }

    public void setAtLast(boolean atLast) {
        isAtLast = atLast;
    }

    public int getZhaDaoNum() {
        return zhaDaoNum;
    }

    public void subZhaDaoNum() {
        this.zhaDaoNum--;
    }

    public int getWinPos() {
        return winPos;
    }

    public int getMaxPointPos() {
        return maxPointPos;
    }

    public TDKSetCard getSetCard() {
        return setCard;

    }

    public boolean isAllQiPai() {
        return isAllQiPai;
    }

    public void setAllQiPai(boolean isAllQiPai) {
        this.isAllQiPai = isAllQiPai;
    }

    public int getQiPaiPos() {
        return qiPaiPos;
    }

    public void setQiPaiPos(int qiPaiPos) {
        this.qiPaiPos = qiPaiPos;
    }

    /**
     * 获取上轮牌最大的Pos
     *
     * @return
     */
    public int getUpperRoundMaxPos() {
        return upperRoundMaxPos;
    }

    /**
     * 设置上轮牌最大的Pos
     *
     * @param upperRoundMaxPos
     */
    public void setUpperRoundMaxPos(int upperRoundMaxPos) {
        this.upperRoundMaxPos = upperRoundMaxPos;
    }

    /**
     * 获取是否烂锅
     *
     * @return
     */
    public boolean isLanGuo() {
        return isLanGuo;
    }

    /**
     * 设置烂锅
     *
     * @param isLanGuo
     */
    public void setLanGuo(boolean isLanGuo) {
        this.isLanGuo = isLanGuo;
    }


    /**
     * 如果是房卡类型，才需要回放记录
     */
    public void roomPlayBack() {
        // 除了房卡类型，其他的都记录回放。
        if (this.checkExistPrizeType(PrizeType.RoomCard)) {
            this.getRoomPlayBack().addPlayBack(new PlayBackData(this.room.getRoomID(), this.getSetID(), dPos, this.room.getCount(), this.room.getRoomKey(), this.room.getBaseRoomConfigure().getGameType().getId(), getPlayBackDateTimeInfo()));
        }
    }


    /**
     * 记录发起解散的玩家
     */
    @Override
    public void addDissolveRoom(BaseSendMsg baseSendMsg) {
        if (SetState.End.equals(this.getState()) || Objects.isNull(this.getSetPosMgr())) {
            return;
        }
        this.getRoomPlayBack().addPlaybackList(baseSendMsg, this.getSetPosMgr().getAllPlayBackNotify());
    }

    @Override
    public void addGameConfig() {
        this.getRoomPlayBack().addPlaybackList(STDK_Config.make(this.getRoom().getCfg(), this.getRoom().getRoomTyepImpl().getRoomTypeEnum()), null);
    }

    public int getCardSize(){
        return this.getRoom().keXuanWanFa(TDKdefine.TDK_KEXUAN.DIYIMIANSI)?TDKSetCard.CARD_SIZE_1:TDKSetCard.CARD_SIZE_2;
    }

    /**
     * 检查是否存在指定消耗类型
     *
     * @return
     */
    @Override
    public boolean checkExistPrizeType(PrizeType prizeType) {
        return prizeType.equals(this.getRoom().getBaseRoomConfigure().getPrizeType());
    }

    public boolean isTiRound() {
        return isTiRound;
    }

    public void setTiRound(boolean tiRound) {
        isTiRound = tiRound;
    }

    public boolean isMoJiaoTiFuRound() {
        return isMoJiaoTiFuRound;
    }

    public void setMoJiaoTiFuRound(boolean moJiaoTiFuRound) {
        isMoJiaoTiFuRound = moJiaoTiFuRound;
    }

    public void setCurOpPos(int curOpPos) {
        this.curOpPos = curOpPos;
    }

    public void setCurChip(int curChip) {
        this.curChip = curChip;
    }

    public int getLanguoBeishu() {
        return languoBeishu;
    }

    public void setLanguoBeishu(int languoBeishu) {
        this.languoBeishu = languoBeishu;
    }

    public void addLanguoBeishu(int cnt) {
        this.languoBeishu += cnt;
    }

    public int getShangFenPos() {
        return shangFenPos;
    }

    public void setShangFenPos(int shangFenPos) {
        this.shangFenPos = shangFenPos;
    }

    public int getShangFenOpTime() {
        return shangFenOpTime;
    }

    public void setShangFenOpTime(int shangFenOpTime) {
        this.shangFenOpTime = shangFenOpTime;
    }

    public boolean getDai2Flag(){
        return this.getRoom().keXuanWanFa(TDKdefine.TDK_KEXUAN.DAI2);
    }
}
